-module(float_yaml11).

-include_lib("eunit/include/eunit.hrl").

-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").

setup() ->
    application:start(yamerl).

schema_failsafe_float_ext_simple_test_() ->
    {setup,
      fun setup/0,
      [
        ?_assertMatch(
          [
            [
              12.34, 12.34, -12.34,
              "12e10", "+12e10", "-12e10",
              "1.2e11", 1.2e+11, 1.2e-11,
              "1.0e10", "1.0E10",
              ".", 0.1, 0.0, 1.0, 1000.0,
              685230.15, 685230.15, -685230.15,
              '+inf', '+inf', '-inf', 'nan',
              '+inf', '+inf', ".iNF",
              'nan', 'nan', ".Nan", ".nAN",
              "Not a float.0e+10", "+Not a float.0e+10", "-Not a float.0e+10"
            ]
          ],
          yamerl_constr:file(?FILENAME, [{detailed_constr, false}])
        )
      ]
    }.

schema_failsafe_float_ext_detailed_test_() ->
    {setup,
      fun setup/0,
      [
        ?_assertMatch(
          [{yamerl_doc,
              {yamerl_seq,yamerl_node_seq,"tag:yaml.org,2002:seq",
                [{line,3},{column,1}],
                [
                  {yamerl_float,yamerl_node_float_ext,
                    "tag:yaml.org,2002:float",
                    [{line,3},{column,4}],
                    12.34},
                  {yamerl_float,yamerl_node_float_ext,
                    "tag:yaml.org,2002:float",
                    [{line,4},{column,3}],
                    12.34},
                  {yamerl_float,yamerl_node_float_ext,
                    "tag:yaml.org,2002:float",
                    [{line,5},{column,3}],
                    -12.34},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,7},{column,4}],
                    "12e10"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,8},{column,3}],
                    "+12e10"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,9},{column,3}],
                    "-12e10"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,11},{column,3}],
                    "1.2e11"},
                  {yamerl_float,yamerl_node_float_ext,
                    "tag:yaml.org,2002:float",
                    [{line,12},{column,3}],
                    1.2e11},
                  {yamerl_float,yamerl_node_float_ext,
                    "tag:yaml.org,2002:float",
                    [{line,13},{column,3}],
                    1.2e-11},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,15},{column,3}],
                    "1.0e10"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,16},{column,3}],
                    "1.0E10"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,18},{column,4}],
                    "."},
                  {yamerl_float,yamerl_node_float_ext,
                    "tag:yaml.org,2002:float",
                    [{line,19},{column,4}],
                    0.1},
                  {yamerl_float,yamerl_node_float_ext,
                    "tag:yaml.org,2002:float",
                    [{line,20},{column,4}],
                    0.0},
                  {yamerl_float,yamerl_node_float_ext,
                    "tag:yaml.org,2002:float",
                    [{line,21},{column,3}],
                    1.0},
                  {yamerl_float,yamerl_node_float_ext,
                    "tag:yaml.org,2002:float",
                    [{line,22},{column,3}],
                    1000.0},
                  {yamerl_float,yamerl_node_float_ext,
                    "tag:yaml.org,2002:float",
                    [{line,24},{column,4}],
                    685230.15},
                  {yamerl_float,yamerl_node_float_ext,
                    "tag:yaml.org,2002:float",
                    [{line,25},{column,3}],
                    685230.15},
                  {yamerl_float,yamerl_node_float_ext,
                    "tag:yaml.org,2002:float",
                    [{line,26},{column,3}],
                    -685230.15},
                  {yamerl_float,yamerl_node_float_ext,
                    "tag:yaml.org,2002:float",
                    [{line,28},{column,4}],
                    '+inf'},
                  {yamerl_float,yamerl_node_float_ext,
                    "tag:yaml.org,2002:float",
                    [{line,29},{column,3}],
                    '+inf'},
                  {yamerl_float,yamerl_node_float_ext,
                    "tag:yaml.org,2002:float",
                    [{line,30},{column,3}],
                    '-inf'},
                  {yamerl_float,yamerl_node_float_ext,
                    "tag:yaml.org,2002:float",
                    [{line,31},{column,4}],
                    nan},
                  {yamerl_float,yamerl_node_float_ext,
                    "tag:yaml.org,2002:float",
                    [{line,33},{column,3}],
                    '+inf'},
                  {yamerl_float,yamerl_node_float_ext,
                    "tag:yaml.org,2002:float",
                    [{line,34},{column,3}],
                    '+inf'},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,35},{column,3}],
                    ".iNF"},
                  {yamerl_float,yamerl_node_float_ext,
                    "tag:yaml.org,2002:float",
                    [{line,37},{column,3}],
                    nan},
                  {yamerl_float,yamerl_node_float_ext,
                    "tag:yaml.org,2002:float",
                    [{line,38},{column,3}],
                    nan},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,39},{column,3}],
                    ".Nan"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,40},{column,3}],
                    ".nAN"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,42},{column,4}],
                    "Not a float.0e+10"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,43},{column,3}],
                    "+Not a float.0e+10"},
                  {yamerl_str,yamerl_node_str,"tag:yaml.org,2002:str",
                    [{line,44},{column,3}],
                    "-Not a float.0e+10"}],
                33}}],
          yamerl_constr:file(?FILENAME, [{detailed_constr, true}])
        )
      ]
    }.
